home *** CD-ROM | disk | FTP | other *** search
- // Rot13.c - Written by Stefan Arentz, August 1993
-
- #include <THINK Power Extensions.h>
-
- void Rot13(char *textPtr, long textLength);
-
- pascal void main(ExternalCallbackBlock *theCallbacks, WindowPtr theWindow) {
-
- Handle theText, theResult;
- long textLength;
- long selStart, selEnd, firstChar;
-
- theText = theCallbacks->GetWindowContents(theWindow);
- if (theText) {
-
- textLength = GetHandleSize(theText);
- theCallbacks->GetSelection(&selStart, &selEnd, &firstChar);
-
- if (selStart == selEnd) {
- selStart = 0;
- selEnd = textLength;
- }
-
- if (textLength){
-
- theResult = NewHandle(selEnd - selStart);
- if (theResult) {
-
- BlockMove(*theText + selStart, *theResult, selEnd - selStart);
- Rot13(*theResult, selEnd - selStart);
- (void) theCallbacks->Paste(theResult);
- theCallbacks->SetSelection(selStart, selEnd, selStart);
- DisposeHandle(theResult);
-
- }
-
- }
-
- }
-
- }
-
- void Rot13(char *textPtr, long textLength) {
-
- while (textLength--) {
-
- if (*textPtr >= 'A' && *textPtr <= 'Z') {
-
- *textPtr = ((*textPtr - 'A' + 13) % 26) + 'A';
-
- } else if (*textPtr >= 'a' && *textPtr <= 'z') {
-
- *textPtr = ((*textPtr - 'a' + 13) % 26) + 'a';
-
- }
-
- textPtr++;
-
- }
-
- }
-